<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>老师信息</title>
    <style>
        #container {
            width: 80%;
            margin: 10px auto;
        }
        .teacher {
            width: 100%;
            margin: 0 auto;
            padding: 10px 0;
            border-bottom: 1px dashed gray;
            overflow: auto;
        }
        .teacher div {
            float: left;
        }
        .photo {
            height: 120px;
            width: 160px;
            {#border-radius: 75px;#}
            overflow: hidden;
            margin-left: 10px;
        }
        .info {
            width: 75%;
            margin-left: 30px;
        }
        .info div {
            clear: both;
            margin: 5px 10px;
        }
        .info span {
            margin-right: 25px;
        }
        .info a {
            text-decoration: none;
            color: blue;
        }
        .user {
            float: right;
            margin: 10px 10px;
        }
        .user+h1 {
            clear: both;
        }
        #photo {
            border-radius: 32px 32px 32px 32px;
        }
    </style>
</head>
<body>
    <div id="container">
        {% if not teachers %}
            <h1>暂无该角色</h1>
        {% endif %}

        {% for teacher in teachers %}
             <h1>{{ name }}</h1>
        <hr>
        <div class="teacher">
            <div class="photo">
                <img src="/static/{{ teacher.photo }}" height="140" alt="">
            </div>
            <div class="info">
                <div>
                    <span><strong>姓名：{{teacher.name}}</strong></span>
                    <span style="color: #ffbd09"><strong>💥身份：{{ teacher.hero }}</strong></span>
                    <span><strong>性别：{{ teacher.gender | yesno:"男,女" }}</strong></span>
                </div>
                <div class="intro">
                    {{ teacher.intro }}
                </div>
                <div class="comment">
                    <a href="/polls/praise/?tno={{ teacher.no }}">👍好评</a>&nbsp;&nbsp;(<strong>{{ teacher.good_count }}</strong>)
                    &nbsp;&nbsp;&nbsp;&nbsp;
                    <a href="/polls/badReview/?tno={{ teacher.no }}">👎差评</a>&nbsp;&nbsp;(<strong>{{ teacher.bad_count }}</strong>)
                </div>
            </div>
        </div>

        {% endfor %}
    </div>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script>
        $(() => {
            $('.comment>a').on('click',(evt) => {
                evt.preventDefault()
                let url = $(evt.target).attr('href')
                $.getJSON(url,(json) => {
                    if(json.code === 200){
                        $(evt.target).next().text(json.count)
                    }else if(json.code === 101){
                            alert(json.msg)
                            let backurl =btoa(location.pathname+location.search)
                            location.href='/polls/login/?backurl='+backurl
                    }
                })
            })
        })
    </script>
</body>
</html>